//监听消息内容
setInterval(function(){
    //console.log(1);
 $.post("listen.jsp",{
     require:"content"
 },function(data){
     data = data.trim();
     //console.log("数据："+data)
     var infos = data.split("\|");
     //console.log("数据项："+infos);
     var table = document.getElementById('tid');
     var row = table.rows.length;
     if(row/2 < infos.length && data != ""){
         for(var i=row/2;i<infos.length;i++){
             var rowInfo = infos[i].split("::");
             //console.log("数据项处理："+data[i]);
             var headInfo = rowInfo[0];
             var bodyInfo = rowInfo[1];
             var trObj1 = document.createElement("tr");
             var tdObj1 = document.createElement("td");
             tdObj1.innerHTML = headInfo;
             trObj1.appendChild(tdObj1);
             var trObj2 = document.createElement("tr");
             var tdObj2 = document.createElement("td");
             tdObj2.innerHTML = bodyInfo;
             trObj2.appendChild(tdObj2);
             table.appendChild(trObj1);
             table.appendChild(trObj2);
         }
     }
 });
},500);
//监听在线人数
setInterval(function(){
    $.post("listen.jsp",{
        require:"numOfPeop"
    },function (data) {
        var numOfPeop = document.getElementById("numOfPeop").innerText;
        if(numOfPeop != data){
            document.getElementById("numOfPeop").innerHTML = data;
        }
    });
},500);
//监听在线人员名单
setInterval(function (){
    $.post("listen.jsp",{
        require:"peopList"
    },function (data) {
        var datas = data.split("-");
        var tab = document.getElementById("ppl");
        var numOfPeop1 = tab.rows.length-1;
        var numOfPeop2 = datas[1];
        if(numOfPeop2 != numOfPeop1){
            var trList = document.getElementsByClassName("ppp");
            for(var i=0;i<numOfPeop1;i++){
                var tr = trList[0];
                var par = tr.parentNode;
                par.removeChild(tr);
            }
            var ndata = datas[0].substr(1,datas[0].length-2);
            var peopList = ndata.split(",");
            for(var i=0;i<peopList.length;i++){
                var name = peopList[i];
                var tr = document.createElement("tr");
                tr.setAttribute("class","ppp");
                var td = document.createElement("td");
                td.innerHTML = name;
                tr.appendChild(td);
                tab.appendChild(tr);
            }
        }
    });
},500);

function send(){
    var content = document.getElementById("chatcon").value;
    //console.log("send()："+content);
    document.getElementById("chatcon").value = "";
    $.post("chatInfo.jsp",{
        chatInfo:content
    },function (data){});
}